<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台管理系统 - 权益明账通</title>
    <style>
        /* 全局样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Helvetica Neue', Arial, sans-serif;
            background-color: #f5f7fa;
            color: #333;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 顶部导航栏 */
        .top-nav {
            background-color: #1976d2;
            color: white;
            padding: 1rem 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }

        .top-nav h1 {
            font-size: 1.5rem;
            font-weight: 600;
        }

        .logout-btn {
            background: rgba(255, 255, 255, 0.2);
            color: white;
            border: none;
            padding: 0.5rem 1rem;
            border-radius: 4px;
            cursor: pointer;
            transition: background 0.3s;
        }

        .logout-btn:hover {
            background: rgba(255, 255, 255, 0.3);
        }

        /* 主要内容区域 */
        .main-container {
            display: flex;
            flex: 1;
        }

        /* 左侧导航栏 */
        .sidebar {
            width: 280px;
            background: white;
            box-shadow: 2px 0 5px rgba(0,0,0,0.1);
            padding: 1.5rem 0;
        }

        .user-info {
            padding: 0 1.5rem 1.5rem;
            border-bottom: 1px solid #eee;
            margin-bottom: 1rem;
        }

        .user-info h3 {
            color: #1976d2;
            margin-bottom: 0.5rem;
            font-size: 1.1rem;
        }

        .username-display {
            background: #f5f7fa;
            padding: 0.75rem;
            border-radius: 4px;
            font-weight: 500;
            color: #555;
        }

        .nav-section {
            margin-bottom: 1.5rem;
        }

        .nav-section h4 {
            padding: 0 1.5rem;
            color: #666;
            font-size: 0.9rem;
            margin-bottom: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .nav-item {
            display: block;
            padding: 0.75rem 1.5rem;
            color: #555;
            text-decoration: none;
            transition: all 0.3s;
            border-left: 3px solid transparent;
        }

        .nav-item:hover {
            background: #f5f7fa;
            color: #1976d2;
            border-left-color: #1976d2;
        }

        .nav-item.active {
            background: #e3f2fd;
            color: #1976d2;
            border-left-color: #1976d2;
            font-weight: 500;
        }

        /* 右侧内容区域 */
        .content {
            flex: 1;
            padding: 2rem;
            background: #f5f7fa;
        }

        .content-header {
            background: white;
            border-radius: 8px;
            padding: 1.5rem;
            margin-bottom: 1.5rem;
            box-shadow: 0 2px 5px rgba(0,0,0,0.05);
        }

        .content-header h2 {
            color: #1976d2;
            margin-bottom: 0.5rem;
        }

        .content-body {
            background: white;
            border-radius: 8px;
            padding: 1.5rem;
            box-shadow: 0 2px 5px rgba(0,0,0,0.05);
            min-height: 400px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #666;
        }

        .welcome-message {
            text-align: center;
            max-width: 500px;
        }

        .welcome-message h3 {
            color: #1976d2;
            margin-bottom: 1rem;
        }

        .welcome-message p {
            line-height: 1.6;
            margin-bottom: 1.5rem;
        }

        /* 加载状态 */
        .loading {
            text-align: center;
            padding: 2rem;
            color: #666;
        }

        .loading::after {
            content: '...';
            animation: dots 1.5s steps(4, end) infinite;
        }

        @keyframes dots {
            0%, 20% { color: rgba(0,0,0,0); text-shadow: .25em 0 0 rgba(0,0,0,0), .5em 0 0 rgba(0,0,0,0); }
            40% { color: #666; text-shadow: .25em 0 0 rgba(0,0,0,0), .5em 0 0 rgba(0,0,0,0); }
            60% { text-shadow: .25em 0 0 #666, .5em 0 0 rgba(0,0,0,0); }
            80%, 100% { text-shadow: .25em 0 0 #666, .5em 0 0 #666; }
        }

        /* 移动端适配 */
        @media (max-width: 768px) {
            .main-container {
                flex-direction: column;
            }
            
            .sidebar {
                width: 100%;
                padding: 1rem 0;
            }
            
            .top-nav {
                padding: 1rem;
            }
            
            .content {
                padding: 1rem;
            }
            
            .nav-items {
                display: flex;
                overflow-x: auto;
            }
            
            .nav-item {
                white-space: nowrap;
                border-left: none;
                border-bottom: 3px solid transparent;
            }
            
            .nav-item.active {
                border-left: none;
                border-bottom-color: #1976d2;
            }
        }
    </style>
</head>
<body>
    <!-- 顶部导航栏 -->
    <nav class="top-nav">
        <h1>权益明账通 - 后台管理系统</h1>
        <button class="logout-btn" id="logoutBtn">退出登录</button>
    </nav>

    <!-- 主要内容区域 -->
    <div class="main-container">
        <!-- 左侧导航栏 -->
        <aside class="sidebar">
            <div class="user-info">
                <h3>当前用户</h3>
                <div class="username-display" id="usernameDisplay">加载中...</div>
            </div>
            
            <div class="nav-section">
                <h4>内容管理</h4>
                <a href="#" class="nav-item active" data-section="video">视频管理</a>
                <a href="#" class="nav-item" data-section="volunteer">志愿者管理</a>
            </div>
        </aside>

        <!-- 右侧内容区域 -->
        <main class="content">
            <div class="content-header">
                <h2 id="contentTitle">视频管理</h2>
                <p>管理平台上的视频内容和相关信息</p>
            </div>
            
            <div class="content-body" id="contentBody">
                <div class="welcome-message">
                    <h3>欢迎使用后台管理系统</h3>
                    <p>请从左侧导航栏选择您要管理的功能模块。系统正在加载中，请稍候...</p>
                    <div class="loading">系统验证中</div>
                </div>
            </div>
        </main>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 获取DOM元素
            const usernameDisplay = document.getElementById('usernameDisplay');
            const contentTitle = document.getElementById('contentTitle');
            const contentBody = document.getElementById('contentBody');
            const logoutBtn = document.getElementById('logoutBtn');
            const navItems = document.querySelectorAll('.nav-item');
            
            // 从cookie获取用户信息
            function getCookie(name) {
                const cookies = document.cookie.split(';');
                for (let cookie of cookies) {
                    const [cookieName, cookieValue] = cookie.trim().split('=');
                    if (cookieName === name) {
                        return decodeURIComponent(cookieValue);
                    }
                }
                return null;
            }
            
            // 验证登录状态
            async function verifyLogin() {
                try {
                    // 从cookie获取认证信息
                    const username = getCookie('username') || 'admin';
                    const password = getCookie('password') || 'admin123';
                    const authid = getCookie('authid') || '0';
                    const authtoken = getCookie('authtoken') || '0';
                    
                    // 发送验证请求
                    const response = await fetch('/api/admin/verify', {
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json'
                        },
                        body: JSON.stringify({
                            username: username,
                            password: password,
                            authid: authid,
                            authtoken: authtoken
                        })
                    });
                    
                    if (!response.ok) {
                        throw new Error('HTTP错误: ' + response.status);
                    }
                    
                    const result = await response.json();
                    
                    if (result.code === 200) {
                        // 登录成功，显示用户名
                        usernameDisplay.textContent = username;
                        showContent('video');
                    } else {
                        // 登录失败，跳转到登录页
                        window.location.href = './login.html';
                    }
                } catch (error) {
                    console.error('验证登录失败:', error);
                    window.location.href = './login.html';
                }
            }
            
            // 显示内容区域
            function showContent(section) {
                // 更新导航激活状态
                navItems.forEach(item => {
                    if (item.getAttribute('data-section') === section) {
                        item.classList.add('active');
                    } else {
                        item.classList.remove('active');
                    }
                });
                
                // 更新内容标题和内容
                if (section === 'video') {
                    contentTitle.textContent = '视频管理';
                    contentBody.innerHTML = `
                        <div class="welcome-message">
                            <h3>视频管理功能</h3>
                            <p>视频管理功能正在开发中，敬请期待...</p>
                            <p>您可以在这里管理平台上的所有视频内容，包括上传、编辑、删除和审核视频。</p>
                        </div>
                    `;
                } else if (section === 'volunteer') {
                    contentTitle.textContent = '志愿者管理';
                    contentBody.innerHTML = `
                        <div class="welcome-message">
                            <h3>志愿者管理功能</h3>
                            <p>志愿者管理功能正在开发中，敬请期待...</p>
                            <p>您可以在这里管理平台上的志愿者信息，包括审核、分配任务和查看志愿者活动记录。</p>
                        </div>
                    `;
                }
            }
            
            // 导航项点击事件
            navItems.forEach(item => {
                item.addEventListener('click', function(e) {
                    e.preventDefault();
                    const section = this.getAttribute('data-section');
                    showContent(section);
                });
            });
            
            // 退出登录
            logoutBtn.addEventListener('click', function() {
                // 清除cookie
                document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
                document.cookie = "password=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
                document.cookie = "authid=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
                document.cookie = "authtoken=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
                
                // 跳转到登录页
                window.location.href = './login.html';
            });
            
            // 页面加载时验证登录状态
            verifyLogin();
            
            // 模拟API响应（实际使用时请删除）
            window.mockVerifyAPI = async function() {
                // 模拟网络延迟
                await new Promise(resolve => setTimeout(resolve, 1000));
                
                // 模拟验证逻辑
                const username = getCookie('username');
                if (username && username !== '0') {
                    return {
                        code: 200,
                        msg: '登录成功',
                        data: null
                    };
                } else {
                    return {
                        code: 0,
                        msg: '未登录',
                        data: null
                    };
                }
            };
        });
    </script>
</body>
</html>